
#import <QuartzCore/QuartzCore.h>
#import "FindLampResultWebViewController.h"
#import "CustomNavigationBar.h"
#import "UINavigationItem+Customization.h"
#import "NSString+VoiceOver.h"

@interface FindLampResultWebViewController ()

@end

@implementation FindLampResultWebViewController

- (id)initWithDefaultNibAndDocumentName:(NSString *)documentName
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        self.documentName = documentName;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CustomNavigationBar *customNavigationBar = (CustomNavigationBar *)self.navigationController.navigationBar;
    
    UIButton* backButton = [customNavigationBar backButtonWith:[UIImage imageNamed:@"btn-back-off.png"] highlight:[UIImage imageNamed:@"btn-back-on.png"] leftCapWidth:14.0 title:self.backButtonTitle];
    backButton.titleLabel.textColor = [UIColor whiteColor];
    backButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.webView.dataDetectorTypes = UIDataDetectorTypeNone;
    self.navigationItem.title = self.title;
    [self.navigationItem customizeTitleInNavigationBarWithHeight:self.navigationController.navigationBar.frame.size.height];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    
    NSString *locale = @"sv";
    NSString *file = [locale stringByAppendingFormat:@"_%@", self.documentName];
    NSLog(@"%@", file);
    NSString *html = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
                                                         pathForResource:file
                                                         ofType:@"html"] 
                                               encoding:NSUTF8StringEncoding error:nil];
    html = [html stringByReplacingOccurrencesOfString:@"../" withString:@""];
    if (voiceoverEnabled) {
        html = [html stringByOptimizingForVoiceOver];
    }
    [self.webView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]]; 
    
    self.topViewSubTitle.text = self.subTitle;
    self.topViewSubTitle.accessibilityLabel = [self.topViewSubTitle.text stringByReplacingOccurrencesOfString:@"–" withString:@"till"];
    self.topViewSubTitle.accessibilityLabel = [self.topViewSubTitle.accessibilityLabel stringByReplacingOccurrencesOfString:@"lm" withString:@"lumen"];
    
    self.tableHeaderViewLabel.text = self.headerViewLabel;
    self.tableHeaderViewLabel.textColor = [UIColor whiteColor];
    self.tableHeaderViewLabel.layer.shadowColor = [UIColor blackColor].CGColor;
    self.tableHeaderViewLabel.layer.shadowOpacity = 0.1;
    self.tableHeaderViewLabel.layer.shadowRadius = 0;
    self.tableHeaderViewLabel.layer.shadowOffset = CGSizeMake(0.0f, -0.9f);

}

- (void)viewDidUnload
{
    [self setTopViewSubTitle:nil];
    [self setTopViewTitle:nil];
    [self setWebView:nil];
    [self setDocumentName:nil];
    [self setBackButtonTitle:nil];
    [self setTableHeaderView:nil];
    [self setTableHeaderViewLabel:nil];
    [self setHeaderViewLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
